package com.meowcook.service.impl;

import com.meowcook.common.AppResult;
import com.meowcook.common.ResultCode;
import com.meowcook.dao.MembersMapper;
import com.meowcook.exception.AppException;
import com.meowcook.pojo.po.Members;
import com.meowcook.service.IMemberService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-11-16
 * Time: 14:31
 */
@Service
public class MemberServiceImpl implements IMemberService {
    @Resource
    private MembersMapper membersMapper;

    @Override
    public ArrayList<Long> selectMemberIdsBySessionId(Long sessionId) {

        return membersMapper.selectUserIdsBySessionId(sessionId);
    }

    @Override
    public void addUncheckNum(Long userId, Long sessionId) {
        Members member = membersMapper.selectUncheckNum(userId, sessionId);
        member.setUncheckNum(member.getUncheckNum() + 1);
        int row = membersMapper.updateByPrimaryKeySelective(member);

        if (row != 1) throw new AppException(AppResult.fail(ResultCode.ERROR_SERVICE));
    }
}
